package com.lanlian.imagelib;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * 网络图片的工具类
 */
public class ShowImageUtils {

    public static void showImageView(Context context, String url, int defaultId, ImageView view) {
        if (context == null) {
            return;
        }
        Glide.with(context).load(url).placeholder(defaultId)
                .error(defaultId).dontAnimate().centerCrop()
                .into(view);
    }

    public static void showRoundImage(Context context, String url, int radius, int defaultId, ImageView view) {
        if (context == null) {
            return;
        }
        Glide.with(context).load(url)
                .bitmapTransform(new CenterCrop(context),
                        new RoundedCornersTransformation(context, DisplayUtil.dip2px(context, radius),
                                0, RoundedCornersTransformation.CornerType.ALL))
                .dontAnimate().placeholder(defaultId).into(view);
    }

    public static void showRoundImage(Context context, int url, int radius, int defaultId, ImageView view) {
        if (context == null) {
            return;
        }
        Glide.with(context).load(url)
                .bitmapTransform(new CenterCrop(context),
                        new RoundedCornersTransformation(context, DisplayUtil.dip2px(context, radius),
                                0, RoundedCornersTransformation.CornerType.ALL))
                .dontAnimate().placeholder(defaultId).into(view);
    }

    public static void showImageViewFitCenter(Context context, String url, int defaultId, ImageView view) {
        if (context == null) {
            return;
        }
        Glide.with(context).load(url).placeholder(defaultId)
                .error(defaultId).dontAnimate().fitCenter()
                .into(view);
    }

}